package oct2013;

public class RemoveDuplicatesfromSortedArrayII {
	public int removeDuplicates(int[] A) {
		int n = A.length;
		int i = 0, j = 0;
		while (j < n) {
			A[i++] = A[j++];
			if (j < n && A[j] == A[j - 1]) {
				A[i++] = A[j++];
			}
			while (j < n && A[j] == A[j - 1]) {
				j++;
			}
		}
		return i;
	}
}
